package com.heima.wemedia.controller.v1;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.heima.common.exception.CustException;
import com.heima.model.common.constants.wemedia.WmMaterialConstant;
import com.heima.model.common.dtos.PageResponseResult;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import com.heima.model.wemedia.dtos.NewsAuthDTO;
import com.heima.model.wemedia.dtos.WmNewsDTO;
import com.heima.model.wemedia.dtos.WmNewsDownOrUpDTO;
import com.heima.model.wemedia.dtos.WmNewsPageReqDTO;
import com.heima.model.wemedia.pojos.WmNews;
import com.heima.wemedia.service.WmNewsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/news")
@Api(value = "自媒体文章controller",tags = "自媒体controller")
public class WmNewsControler {

    @Autowired
    WmNewsService wmNewsService;

    @PostMapping("/list")
    @ApiOperation(value = "分页待条件查询自媒体文章列表")
    public PageResponseResult list(@RequestBody WmNewsPageReqDTO dto){
        return wmNewsService.list(dto);
    }


    @PostMapping("/submit")
    @ApiOperation(value = "自媒体文章发布,修改,保存草稿")
    public ResponseResult submit(@RequestBody WmNewsDTO dto){
        return wmNewsService.submit(dto);
    }

    @GetMapping("/one/{id}")
    @ApiOperation(value = "根据id查询文章")
    public ResponseResult findWmNewsById(@PathVariable Integer id){
        return wmNewsService.findWmNewsById(id);
    }

    @GetMapping("/del_news/{id}")
    @ApiOperation(value = "根据id删除文章")
    public ResponseResult delNewsById(@PathVariable Integer id){
        return wmNewsService.delNewsById(id);
    }

    @PostMapping("/down_or_up")
    @ApiOperation("下架文章")
    public ResponseResult downOrUp(@RequestBody WmNewsDownOrUpDTO dto){

        return wmNewsService.downOrUp(dto);
    }


    /**
     * 查询文章列表
     * @param dto
     * @return
     */
    @PostMapping("/list_vo")
    public ResponseResult findList(@RequestBody NewsAuthDTO dto) {
        return wmNewsService.findList(dto);
    }

    /**
     * 查询文章详情
     * @param id
     * @return
     */
    @GetMapping("/one_vo/{id}")
    public ResponseResult findWmNewsVo(@PathVariable("id") Integer id) {
        return wmNewsService.findWmNewsVo(id);
    }

    @PostMapping("/auth_pass")
    @ApiOperation("人工审核文章通过 修改状态为4")
    public ResponseResult authPass(@RequestBody NewsAuthDTO dto){
         return wmNewsService.updaStatus(dto,WmMaterialConstant.WM_NEWS_AUTH_PASS);
    }

    @PostMapping("/auth_fail")
    @ApiOperation("人工审核文章驳回 修改状态为2")
    public ResponseResult authFail(@RequestBody NewsAuthDTO dto){
        return  wmNewsService.updaStatus(dto,WmMaterialConstant.WM_NEWS_AUTH_FAIL);
    }

    /**
     * 修改文章
     * @param wmNews
     * @return
     */
    @ApiOperation("根据id修改自媒体文章")
    @PutMapping("/update")
    public ResponseResult updateWmNews(@RequestBody WmNews wmNews) {
        wmNewsService.updateById(wmNews);
        return ResponseResult.okResult();
    }
}
